<template>
  <el-card>
    <!-- 标题 -->
    <template #header>
      <h2>{{papername}}答卷分析</h2>
    </template>
    <ve-line :data="chartData"></ve-line>

  </el-card>
</template>

<script>
export default {
  props: ['id', 'papername'],
  data() {
    return {
      res: {},
      chartData: {
        columns: ['item', 'num'],
        rows: [],
      },
    };
  },
  async created() {
    const { data: { result } } = await this.apis.getAnswers(this.id);
    result.forEach((el1) => {
      el1.outlines.forEach((el2) => {
        if (this.res[el2.answer]) {
          this.res[el2.answer] += 1;
        } else {
          this.res[el2.answer] = 1;
        }
      });
    });
    Object.keys(this.res).forEach((el) => {
      const re = {
        item: el,
        num: this.res[el],
      };
      this.chartData.rows.push(re);
    });
  },
};
</script>
